<?php

    ##################################################
    #
    # Copyright (c) 2004-2006 OIC Group, Inc.
    # Written and Designed by James Hunt
    #
    # This file is part of Exponent
    #
    # Exponent is free software; you can redistribute
    # it and/or modify it under the terms of the GNU
    # General Public License as published by the Free
    # Software Foundation; either version 2 of the
    # License, or (at your option) any later version.
    #
    # GPL: http://www.gnu.org/licenses/gpl.txt
    #
    ##################################################

    if (!defined('EXPONENT')) exit('');

    //overides function html entity decode
    function exponent_unhtmlentities( $str )
    {
        $trans = get_html_translation_table(HTML_ENTITIES);
        $trans['&apos;'] = '\'';
        $trans=array_flip($trans);

        $trans['&apos;'] = '\'';
        $trans['&#039;'] = '\'';
        return strtr($str, $trans);
    }

    if (!defined('SYS_SESSIONS')) 
    {
        include(BASE."subsystems/sessions.php");	
        exponent_sessions_initialize();
    }
    
    // Initialize the language subsystem
    require_once(BASE.'subsystems/lang.php');
    // we need to initialize the language system this time because we need to check language prefix
    
    $language = exponent_sessions_get("language");
    
    // determine which language on URL
    $url = $_SERVER['REQUEST_URI'];
    $lang_prefix = exponent_lang_extract_prefix_fromURL($url);
    $langs_full = exponent_lang_full();
    $lang_in_url="";
    foreach ($langs_full as $k=>$v)
        if ($v['url_prefix'] == $lang_prefix)
        {
            $lang_in_url = $v['lang_code'];
            break;
        }
    
    if ($lang_in_url != "")
        $language = $lang_in_url;
    
    //echo $language;
    if(!isset($language)){
        @include_once(BASE."conf/config.php");
    }
    else{
        @include_once(BASE."conf/profiles/Default_{$language}.php");
    }
    exponent_sessions_set("language", $language);
    

    if (is_readable(BASE."conf/extensions")) {
        $dh = opendir(BASE."conf/extensions");
        while (($file = readdir($dh)) !== false) {
            if (is_readable(BASE."conf/extensions/$file") && substr($file,-13,13) == ".defaults.php") {
                include_once(BASE."conf/extensions/$file");
            }
        }
    }

?>
